"use strict";
const bag = 91;
const dataset = require("cosjs.updater").dataset;
const mvc = require('cosjs.mvc');
class daily extends dataset.hash {
    constructor(updater) {
        super(updater, bag, 'daily');
        this.sort = bag;
        this.sort = 102;
    }
    add(key, val) {
        return this.act('add', key, val);
    }
    act(t, k, v) {
        let act;
        let _id = this.model.ObjectID(this.model.uid);
        if (arguments.length === 1) {
            act = arguments[0]
        }
        else {
            act = { "_id": _id, "t": t, "k": k, "v": v, "b": this.bag };
        }
        act["_id"] = _id;
        if (act.t !== "set") {
            act.v = Number(act.v);
            if (!act.v) { return; }
            this.key(act.k);
        }

        this._acts.push(act);
        let dailyCache = mvc.model.redis("dailyCache", this.updater.sid);
        let ttl = 1 * 24 * 3600; //有效期1天
        dailyCache.set(this.model.uid, this._acts, ttl);
        if (this._update && typeof hash_act_parser[act.t] === 'function') {
            hash_act_parser[act.t].call(this, act);
        }
    }
};

module.exports = daily;